const Cookies = {
  // 设置cookie
  set: (key, value, expires) => {
    var cookieText =
      encodeURIComponent(key) + "=" + encodeURIComponent(value) + ";path=/";
    if (!isNaN(expires)) {
      var date = new Date();
      date.setDate(date.getDate() + expires);
      cookieText += ";expires=" + date;
    }
    document.cookie = cookieText;
  },
  // 获取cookie
  get: (key) => {
    var arr = document.cookie.split("; ");
    for (var i = 0, len = arr.length; i < len; i++) {
      var list = arr[i].split("=");
      if (encodeURIComponent(key) === list[0]) {
        return decodeURIComponent(list[1]);
      }
    }
  },
  // 删除cookie
  remove: (key) => {
    document.cookie =
      encodeURIComponent(key) + "=;path=/;expires=" + new Date(0);
  },
};

const TokenKey = "vue_admin_template_token";

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  return Cookies.set(TokenKey, token);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}
